package br.com.seosoft.simplecalcfinan.adapters;

import java.util.List;

import br.com.seosoft.simplecalcfinan.R;
import br.com.seosoft.simplecalcfinan.geral;
import br.com.seosoft.simplecalcfinan.R.id;
import br.com.seosoft.simplecalcfinan.R.layout;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListaAdapter extends BaseAdapter {

	private Context context;
	private List<geral> geralList;

	public ListaAdapter(Context context, List<geral> geralList) {
		this.context = context;
		this.geralList = geralList;
	}

	@Override
	public int getCount() {
		return geralList.size();
	}

	@Override
	public Object getItem(int position) {
		return geralList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public boolean isEmpty() {
		// TODO Auto-generated method stub
		return geralList.isEmpty();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// Recupera o estado da posi����o atual
		geral geral = geralList.get(position);

		// Cria uma inst��ncia do layout XML para os objetos correspondentes
		// na View
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.lista_grupos, null);

		// DESCRICAO GRUPO
		TextView textDescricao = (TextView) view
				.findViewById(R.id.CampoDescricao);
		textDescricao.setText(geral.getDescGrupo());

		// SALDO CONTAS
		TextView textSaldoContas = (TextView) view
				.findViewById(R.id.CampoValor);
		textSaldoContas.setText(geral.DecimalCurrency(geral
				.getTotalContasGrupo()));

		// MODIFICA CORES

		if (geral.getDescGrupo().equalsIgnoreCase("SMS.BANCOS")) {

			textDescricao.setTextColor(Color.BLUE);

		}

		textSaldoContas
				.setTextColor(geral.mudarCor(geral.getTotalContasGrupo()));

		return view;
	}

}
